package com.zc.study.thread.多线程第三章节.thread3_1_11;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        String lock = new String();
        C c = new C(lock);
        P p = new P(lock);
        ThreadC[] threadC = new ThreadC[2];
        ThreadP[] threadP = new ThreadP[2];
        for(int i = 0;i<2;i++){
            threadC[i] = new ThreadC(c);
            threadC[i].setName("消费者"+(i+1));
            threadP[i] =new ThreadP(p);
            threadP[i].setName("生产者"+(i+1));
            threadC[i].start();
            threadP[i].start();
        }
        Thread.sleep(5000);
        Thread[] threadArray = new Thread[Thread.currentThread().getThreadGroup().activeCount()];
        Thread.currentThread().getThreadGroup().enumerate(threadArray);
        for(int i= 0;i<threadArray.length;i++){
            System.out.println(threadArray[i].getName()+""+threadArray[i].getState());
        }
    }
}
